﻿// Write methods to calculate minimum, maximum, average, sum and product of given set of integer numbers.
// Use variable number of arguments.

using System;

class FunctionWithNumbersSet
{
    static void Main()
    {
        dynamic min = Min(2.6m, 5.8m, 0.1m, -6m, decimal.MaxValue);
        Console.WriteLine("Minimum of the numbers set is: {0}", min);

        dynamic max = Max(1f, 2f, 9f, 0.6f, -5f, 22f, 123.1f, -123f, 0f);
        Console.WriteLine("Maximum of the numbers set is: {0}", max);
        
        decimal average = Average(0, 1, 10, 5, 5, 12, -3, 4, 444);
        Console.WriteLine("Average of the numbers set is: {0}", average);
        
        dynamic sum = Sum(55.76, 45, 105.55, 0.78, -5);
        Console.WriteLine("Sum of the numbers set is: {0}", sum);
        
        dynamic product = Product(60, 2, 3, 1);
        Console.WriteLine("Product of the numbers set is: {0}", product);
    }

    private static Т Min<Т>(params Т[] numbers)
    {
        dynamic min = int.MaxValue;
        int length = numbers.Length;
        for (int i = 0; i < length; i++)
        {
            if (numbers[i] < min)
            {
                min = numbers[i];
            }
        }

        return min;
    }

    private static T Max<T>(params T[] numbers)
    {
        dynamic max = int.MinValue;
        int length = numbers.Length;
        for (int i = 0; i < length; i++)
        {
            if (numbers[i] > max)
            {
                max = numbers[i];
            }
        }

        return max;
    }

    private static decimal Average<T>(params T[] numbers)
    {
        dynamic sum = 0;
        decimal count = 0m;
        foreach (T item in numbers)
        {
            if (!item.Equals(0))
            {
                sum += item;
            }
            count++;
        }
        dynamic average = sum / count;

        return average;
    }

    private static T Sum<T>(params T[] numbers)
    {
        dynamic sum = 0;
        foreach (T item in numbers)
        {
            if (!item.Equals(0))
            {
                sum += item;
            }
        }

        return sum;
    }

    private static T Product<T>(params T[] numbers)
    {
        dynamic product = 1;
        foreach (T item in numbers)
        {
            product *= item;
        }

        return product;
    }
}